package cs.sy.service.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cs.sy.service.bean.UserBean;
import cs.sy.service.business.UserLoginBuss;

public class RepairPassServlet extends HttpServlet{

	private static final long serialVersionUID = 1L;
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		try{
			String pass = req.getParameter("p1");
			UserBean user = (UserBean)req.getSession().getAttribute("user");
			int id = user.getId();
			if(new UserLoginBuss().repairPass(pass, id)){
				req.setAttribute("result", "密码修改成功...");
				req.getRequestDispatcher("/u_login.jsp").forward(req, resp);
			}
		}catch (Exception e) {
			req.setAttribute("result", "密码修改失败...");
			req.getRequestDispatcher("/u_login.jsp").forward(req, resp);
		}
	}
	
}
